<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MC823 - Laboratório de Redes: Trabalho 01: Código-Fonte de resposta.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Gerado por Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Busca');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">MC823 - Laboratório de Redes: Trabalho 01</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Página&#160;Principal</span></a></li>
      <li><a href="annotated.html"><span>Estruturas&#160;de&#160;Dados</span></a></li>
      <li class="current"><a href="files.html"><span>Arquivos</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Busca" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Lista&#160;de&#160;Arquivos</span></a></li>
      <li><a href="globals.html"><span>Globais</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">resposta.c</div>  </div>
</div>
<div class="contents">
<a href="resposta_8c.html">Vá para a documentação deste arquivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="resposta_8h.html">resposta.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include&lt;string.h&gt;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a><a class="code" href="resposta_8c.html#a281d136eba7bc38021f2fccbf61a633f">00004</a> <span class="preprocessor">#define NUM_MAX_DISCIPLINAS 10</span>
<a name="l00005"></a><a class="code" href="resposta_8c.html#a5d429b813e4525632cd4064f5e47213e">00005</a> <span class="preprocessor"></span><span class="preprocessor">#define TAM_MAX_NOME_DISCIPLINA 120</span>
<a name="l00006"></a>00006 <span class="preprocessor"></span>
<a name="l00007"></a>00007 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00018"></a>00018 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00019"></a><a class="code" href="resposta_8h.html#a9bb7e31e6340d62b3afb839655847563">00019</a> <span class="keywordtype">char</span> * <a class="code" href="resposta_8c.html#a9bb7e31e6340d62b3afb839655847563">preparaResposta</a>(<span class="keywordtype">char</span> *buf) {
<a name="l00020"></a>00020     <span class="keywordtype">char</span> *resposta;
<a name="l00021"></a>00021     <span class="keywordtype">char</span> *disc;
<a name="l00022"></a>00022 
<a name="l00023"></a>00023     <span class="keywordflow">if</span>(buf[0] == <span class="charliteral">&#39;l&#39;</span>){
<a name="l00024"></a>00024         <span class="keywordflow">return</span> resposta = <a class="code" href="resposta_8c.html#adca402fde30bac4845d32a7dd4e6160a">listaDisciplinas</a>();
<a name="l00025"></a>00025     }
<a name="l00026"></a>00026     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(buf[0] == <span class="charliteral">&#39;p&#39;</span>){
<a name="l00027"></a>00027         <span class="comment">//Copia a disciplina</span>
<a name="l00028"></a>00028         disc= strndup(buf+1, 5);
<a name="l00029"></a>00029         <span class="keywordflow">return</span> resposta =  <a class="code" href="resposta_8c.html#ae53e5d927eddd073efa7dd3777c222c2">programaDisciplina</a>(disc);
<a name="l00030"></a>00030     }
<a name="l00031"></a>00031     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(buf[0] == <span class="charliteral">&#39;i&#39;</span>){
<a name="l00032"></a>00032         <span class="comment">//Copia a disciplina</span>
<a name="l00033"></a>00033         disc = strndup(buf+1, 5);
<a name="l00034"></a>00034         <span class="keywordflow">if</span>(strcmp(disc, <span class="stringliteral">&quot;&quot;</span>) ==0){
<a name="l00035"></a>00035             <span class="comment">//lista as informações de todas as disciplinas</span>
<a name="l00036"></a>00036             <span class="keywordflow">return</span> resposta = <a class="code" href="resposta_8c.html#aae0e9c217f1ede36bbf9821b36bba3f9">infoDisciplinas</a>();
<a name="l00037"></a>00037         }
<a name="l00038"></a>00038         <span class="keywordflow">else</span>{
<a name="l00039"></a>00039             <span class="comment">//lista as informações de disc</span>
<a name="l00040"></a>00040             <span class="keywordflow">return</span> resposta = <a class="code" href="resposta_8c.html#a6c04d45a3b24b43c86d50889bde25d67">infoDisciplina</a>(disc);
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042     }
<a name="l00043"></a>00043     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(buf[0] == <span class="charliteral">&#39;w&#39;</span>){
<a name="l00044"></a>00044         <span class="keywordtype">char</span>* comentario;
<a name="l00045"></a>00045         <span class="comment">//Copia a disciplina</span>
<a name="l00046"></a>00046         disc = strndup(buf+1, 5);
<a name="l00047"></a>00047         comentario = strndup(buf+6, strlen(buf));
<a name="l00048"></a>00048         <span class="keywordflow">return</span> resposta = <a class="code" href="resposta_8c.html#a2b6f397b0bfae5590b292d282513c54b">escreveComentario</a>(disc, comentario);
<a name="l00049"></a>00049     }
<a name="l00050"></a>00050     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(buf[0] == <span class="charliteral">&#39;c&#39;</span>){
<a name="l00051"></a>00051         <span class="comment">//Copia a disciplina</span>
<a name="l00052"></a>00052         disc = strndup(buf+1, 5);
<a name="l00053"></a>00053         <span class="keywordflow">return</span> resposta = <a class="code" href="resposta_8c.html#a2a098bc71f2a19dd74318fd778676979">leComentario</a>(disc);
<a name="l00054"></a>00054 
<a name="l00055"></a>00055     }
<a name="l00056"></a>00056     <span class="keywordflow">else</span> <span class="keywordflow">return</span> resposta = <span class="stringliteral">&quot;Algo errado...&quot;</span>;
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00070"></a>00070 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00071"></a><a class="code" href="resposta_8h.html#a2a098bc71f2a19dd74318fd778676979">00071</a> <span class="keywordtype">char</span>* <a class="code" href="resposta_8c.html#a2a098bc71f2a19dd74318fd778676979">leComentario</a>(<span class="keywordtype">char</span>* disc){
<a name="l00072"></a>00072     <span class="keywordtype">char</span> *info, *resposta;
<a name="l00073"></a>00073     <span class="keywordtype">int</span> i, sub, cont=0, j=0;
<a name="l00074"></a>00074     <span class="keywordtype">char</span> *com = <span class="stringliteral">&quot;Comentário:&quot;</span>;
<a name="l00075"></a>00075     <span class="comment">//Retorna uma string com todas as informações da disciplina</span>
<a name="l00076"></a>00076     info = <a class="code" href="resposta_8c.html#a6c04d45a3b24b43c86d50889bde25d67">infoDisciplina</a>(disc);
<a name="l00077"></a>00077     sub = strlen(com);
<a name="l00078"></a>00078     <span class="keywordflow">for</span> (i = 0; i &lt; strlen(info); i++) {
<a name="l00079"></a>00079          <span class="keywordflow">if</span>((info[i] == com[j]) &amp;&amp; (com[j] != <span class="charliteral">&#39;\0&#39;</span>)){
<a name="l00080"></a>00080              printf(<span class="stringliteral">&quot;%c\n&quot;</span>, info[i]);
<a name="l00081"></a>00081              cont++;
<a name="l00082"></a>00082              j++;
<a name="l00083"></a>00083              <span class="keywordflow">if</span>(cont == (sub-1)){
<a name="l00084"></a>00084                 resposta = strndup(info+i+2, strlen(info));
<a name="l00085"></a>00085                 <span class="keywordflow">return</span> resposta;
<a name="l00086"></a>00086              }
<a name="l00087"></a>00087          }
<a name="l00088"></a>00088          <span class="keywordflow">else</span> <span class="keywordflow">if</span>(com[j] != <span class="charliteral">&#39;\0&#39;</span>){
<a name="l00089"></a>00089              cont =0;
<a name="l00090"></a>00090              j = 0;
<a name="l00091"></a>00091          }
<a name="l00092"></a>00092     }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="keywordflow">return</span> <span class="stringliteral">&quot;Houve um erro ao obter o comentário.\n&quot;</span>;
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00110"></a>00110 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00111"></a><a class="code" href="resposta_8h.html#a2b6f397b0bfae5590b292d282513c54b">00111</a> <span class="keywordtype">char</span> * <a class="code" href="resposta_8c.html#a2b6f397b0bfae5590b292d282513c54b">escreveComentario</a>( <span class="keywordtype">char</span> *disc, <span class="keywordtype">char</span> *comentario){
<a name="l00112"></a>00112     FILE *fd;
<a name="l00113"></a>00113     <span class="keywordtype">char</span> text[10];
<a name="l00114"></a>00114    <span class="comment">/* Normaliza e obtem o nome do arquivo correspondente</span>
<a name="l00115"></a>00115 <span class="comment">     * a disciplina passada como parametro*/</span>
<a name="l00116"></a>00116     <a class="code" href="resposta_8c.html#aaf2c986b7320373a463f607a67c07365">uppercase</a>(disc);
<a name="l00117"></a>00117     strcpy(text, disc);
<a name="l00118"></a>00118     strcat(text, <span class="stringliteral">&quot;.txt&quot;</span>);
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     fd = fopen(text, <span class="stringliteral">&quot;a+&quot;</span>);
<a name="l00121"></a>00121     <span class="comment">/* Verifica se a abertura do arquivo foi bem sucedida */</span>
<a name="l00122"></a>00122     <span class="keywordflow">if</span>(fd == NULL){
<a name="l00123"></a>00123         printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo da disciplina %s.\n&quot;</span>, disc);
<a name="l00124"></a>00124         exit(-1);
<a name="l00125"></a>00125     }
<a name="l00126"></a>00126     <span class="keywordflow">else</span>{ 
<a name="l00127"></a>00127         fprintf(fd, <span class="stringliteral">&quot;%s\n&quot;</span>, comentario);
<a name="l00128"></a>00128         fclose(fd);
<a name="l00129"></a>00129         <span class="keywordflow">return</span> <span class="stringliteral">&quot;Comentário escrito com sucesso!\n&quot;</span>;
<a name="l00130"></a>00130     }
<a name="l00131"></a>00131 }
<a name="l00132"></a>00132 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00139"></a>00139 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00140"></a><a class="code" href="resposta_8h.html#adca402fde30bac4845d32a7dd4e6160a">00140</a> <span class="keywordtype">char</span> * <a class="code" href="resposta_8c.html#adca402fde30bac4845d32a7dd4e6160a">listaDisciplinas</a>(){
<a name="l00141"></a>00141     FILE *fd;
<a name="l00142"></a>00142     <span class="keywordtype">string</span> <a class="code" href="structstr.html">str</a>;
<a name="l00143"></a>00143     <span class="keywordtype">int</span> i=0;
<a name="l00144"></a>00144     
<a name="l00145"></a>00145     <span class="comment">/* Inicializa uma string para conter as disciplinas */</span>
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     str = <a class="code" href="str_8c.html#a43e9efab3e78f169462b9f842c827fba">str_initialize</a>(((<span class="keywordtype">size_t</span>)<a class="code" href="resposta_8c.html#a281d136eba7bc38021f2fccbf61a633f">NUM_MAX_DISCIPLINAS</a> * <a class="code" href="resposta_8c.html#a5d429b813e4525632cd4064f5e47213e">TAM_MAX_NOME_DISCIPLINA</a>));
<a name="l00148"></a>00148 
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="comment">/*Abre o arquivo de codigos das disciplinas*/</span>
<a name="l00151"></a>00151     fd = fopen(<span class="stringliteral">&quot;codigo_disciplinas.txt&quot;</span>, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">/* Verifica se a abertura do arquivo foi bem sucedida */</span>
<a name="l00154"></a>00154     <span class="keywordflow">if</span>(fd == NULL){
<a name="l00155"></a>00155         printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo com codigos das disciplinas.\n&quot;</span>);
<a name="l00156"></a>00156         exit(-1);
<a name="l00157"></a>00157     }
<a name="l00158"></a>00158     <span class="keywordflow">else</span>{
<a name="l00159"></a>00159         <span class="comment">/*Arquivo aberto com sucesso*/</span> 
<a name="l00160"></a>00160         <span class="keywordtype">char</span> temp[120];
<a name="l00161"></a>00161         i=0;
<a name="l00162"></a>00162         
<a name="l00163"></a>00163         <span class="keywordflow">while</span>(fgets(temp, <span class="keyword">sizeof</span>(temp), fd) != NULL){
<a name="l00164"></a>00164                     
<a name="l00165"></a>00165             <span class="comment">/*Passa a string lida para a estrutura de strings*/</span>
<a name="l00166"></a>00166             <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, temp, strlen(temp)-1);
<a name="l00167"></a>00167             <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot;\n&quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00168"></a>00168             i++;
<a name="l00169"></a>00169         }
<a name="l00170"></a>00170         fclose(fd);
<a name="l00171"></a>00171     }
<a name="l00172"></a>00172     <span class="keywordflow">return</span> str-&gt;<a class="code" href="structstr.html#a1fc4ce5d6a790001388349ca5b735383">s</a>; 
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00185"></a>00185 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00186"></a><a class="code" href="resposta_8h.html#ae53e5d927eddd073efa7dd3777c222c2">00186</a> <span class="keywordtype">char</span>* <a class="code" href="resposta_8c.html#ae53e5d927eddd073efa7dd3777c222c2">programaDisciplina</a>(<span class="keywordtype">char</span>* disc){
<a name="l00187"></a>00187     
<a name="l00188"></a>00188     FILE *fd;
<a name="l00189"></a>00189     <span class="keywordtype">char</span> texto[10];
<a name="l00190"></a>00190     <span class="keywordtype">string</span> <a class="code" href="structstr.html">str</a>;
<a name="l00191"></a>00191 
<a name="l00192"></a>00192     <span class="comment">/* Normaliza e obtem o nome do arquivo correspondente</span>
<a name="l00193"></a>00193 <span class="comment">     * a disciplina passada como parametro*/</span>
<a name="l00194"></a>00194     <a class="code" href="resposta_8c.html#aaf2c986b7320373a463f607a67c07365">uppercase</a>(disc);
<a name="l00195"></a>00195     strcpy(texto, disc);
<a name="l00196"></a>00196     strcat(texto, <span class="stringliteral">&quot;.txt&quot;</span>);
<a name="l00197"></a>00197 
<a name="l00198"></a>00198     fd = fopen(texto, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00199"></a>00199     <span class="comment">/* Verifica se a abertura do arquivo foi bem sucedida */</span>
<a name="l00200"></a>00200     <span class="keywordflow">if</span>(fd == NULL){
<a name="l00201"></a>00201         printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo da disciplina %s.\n&quot;</span>, disc);
<a name="l00202"></a>00202         exit(-1);
<a name="l00203"></a>00203     }
<a name="l00204"></a>00204     <span class="keywordflow">else</span>{
<a name="l00205"></a>00205         <span class="keywordtype">char</span> tmp[200];
<a name="l00206"></a>00206         <span class="keywordtype">char</span> *pch;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208         <span class="comment">/* Inicializa um vetor contendo a resposta */</span>
<a name="l00209"></a>00209         str = <a class="code" href="str_8c.html#a43e9efab3e78f169462b9f842c827fba">str_initialize</a>(((<span class="keywordtype">size_t</span>)<a class="code" href="resposta_8c.html#a281d136eba7bc38021f2fccbf61a633f">NUM_MAX_DISCIPLINAS</a> * <a class="code" href="resposta_8c.html#a5d429b813e4525632cd4064f5e47213e">TAM_MAX_NOME_DISCIPLINA</a>));
<a name="l00210"></a>00210         
<a name="l00211"></a>00211         <span class="comment">/* Le o titulo da disciplina */</span>
<a name="l00212"></a>00212         fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd);
<a name="l00213"></a>00213 
<a name="l00214"></a>00214         <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, tmp, <span class="keyword">sizeof</span>(tmp) -1);
<a name="l00215"></a>00215 
<a name="l00216"></a>00216         <span class="comment">/* Le o resto do arquivo */</span>
<a name="l00217"></a>00217         <span class="keywordflow">while</span>(fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd)!=NULL){
<a name="l00218"></a>00218             <span class="comment">/* Separa a linha lida */</span>
<a name="l00219"></a>00219             pch = strtok(tmp, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00220"></a>00220             <span class="comment">/* Imprime a linha lida */</span>
<a name="l00221"></a>00221             <span class="keywordflow">while</span>(pch !=NULL){
<a name="l00222"></a>00222                 <span class="comment">/* Para a impressao caso se depare com a palavra &quot;Horário:&quot; */</span>
<a name="l00223"></a>00223                 
<a name="l00224"></a>00224                 <span class="keywordflow">if</span>(strcmp(pch, <span class="stringliteral">&quot;Horário:\n&quot;</span>) ==0){
<a name="l00225"></a>00225                     <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot;\n&quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00226"></a>00226                     fclose(fd);
<a name="l00227"></a>00227                     <span class="keywordflow">return</span> str-&gt;<a class="code" href="structstr.html#a1fc4ce5d6a790001388349ca5b735383">s</a>;
<a name="l00228"></a>00228                 }
<a name="l00229"></a>00229                 <span class="keywordflow">else</span>{
<a name="l00230"></a>00230                     <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, pch, strlen(pch));
<a name="l00231"></a>00231                     <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot; &quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00232"></a>00232                 }
<a name="l00233"></a>00233                 pch = strtok(NULL, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00234"></a>00234                 
<a name="l00235"></a>00235                 
<a name="l00236"></a>00236             }
<a name="l00237"></a>00237             
<a name="l00238"></a>00238 
<a name="l00239"></a>00239         }
<a name="l00240"></a>00240         <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot;\n&quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00241"></a>00241         fclose(fd);
<a name="l00242"></a>00242 
<a name="l00243"></a>00243         <span class="keywordflow">return</span> str-&gt;<a class="code" href="structstr.html#a1fc4ce5d6a790001388349ca5b735383">s</a>;
<a name="l00244"></a>00244     }
<a name="l00245"></a>00245 }
<a name="l00246"></a>00246 
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 
<a name="l00249"></a>00249 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00257"></a>00257 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00258"></a><a class="code" href="resposta_8h.html#aae0e9c217f1ede36bbf9821b36bba3f9">00258</a> <span class="keywordtype">char</span>* <a class="code" href="resposta_8c.html#aae0e9c217f1ede36bbf9821b36bba3f9">infoDisciplinas</a>(){
<a name="l00259"></a>00259     
<a name="l00260"></a>00260     FILE *fd, *nomefd;
<a name="l00261"></a>00261     <span class="keywordtype">char</span> *texto;
<a name="l00262"></a>00262     <span class="keywordtype">string</span> <a class="code" href="structstr.html">str</a>;
<a name="l00263"></a>00263     <span class="keywordtype">char</span> nomedisc[200];
<a name="l00264"></a>00264 
<a name="l00265"></a>00265     nomefd = fopen(<span class="stringliteral">&quot;codigo_disciplinas.txt&quot;</span>, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00266"></a>00266     <span class="keywordflow">if</span>(nomefd == NULL){
<a name="l00267"></a>00267         printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo com nome das disciplinas.\n&quot;</span>);
<a name="l00268"></a>00268         exit(-1);
<a name="l00269"></a>00269     }
<a name="l00270"></a>00270     <span class="keywordflow">else</span>{
<a name="l00271"></a>00271 
<a name="l00272"></a>00272             <span class="comment">/* Inicializa um vetor contendo a resposta */</span>
<a name="l00273"></a>00273             str = <a class="code" href="str_8c.html#a43e9efab3e78f169462b9f842c827fba">str_initialize</a>(((<span class="keywordtype">size_t</span>)<a class="code" href="resposta_8c.html#a281d136eba7bc38021f2fccbf61a633f">NUM_MAX_DISCIPLINAS</a> * <a class="code" href="resposta_8c.html#a5d429b813e4525632cd4064f5e47213e">TAM_MAX_NOME_DISCIPLINA</a>));
<a name="l00274"></a>00274             <span class="keywordflow">while</span>(fgets(nomedisc, <span class="keyword">sizeof</span>(nomedisc), nomefd) !=NULL){
<a name="l00275"></a>00275                 <span class="comment">/* Normaliza e obtem o nome do arquivo correspondente</span>
<a name="l00276"></a>00276 <span class="comment">                * a disciplina passada como parametro*/</span>
<a name="l00277"></a>00277                 <a class="code" href="resposta_8c.html#aaf2c986b7320373a463f607a67c07365">uppercase</a>(nomedisc);
<a name="l00278"></a>00278                 texto = strndup(nomedisc, 5);
<a name="l00279"></a>00279                 strcat(texto, <span class="stringliteral">&quot;.txt&quot;</span>);
<a name="l00280"></a>00280 
<a name="l00281"></a>00281                 fd = fopen(texto, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00282"></a>00282                 <span class="comment">/* Verifica se a abertura do arquivo foi bem sucedida */</span>
<a name="l00283"></a>00283                 <span class="keywordflow">if</span>(fd == NULL){
<a name="l00284"></a>00284                     printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo da disciplina %s.\n&quot;</span>, nomedisc);
<a name="l00285"></a>00285                     exit(-1);
<a name="l00286"></a>00286                 }
<a name="l00287"></a>00287                 <span class="keywordflow">else</span>{
<a name="l00288"></a>00288                     <span class="keywordtype">char</span> tmp[200];
<a name="l00289"></a>00289                     <span class="keywordtype">char</span> *pch;
<a name="l00290"></a>00290 
<a name="l00291"></a>00291                     <span class="comment">/* Le o titulo da disciplina */</span>
<a name="l00292"></a>00292                     fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd);
<a name="l00293"></a>00293                     <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, tmp, <span class="keyword">sizeof</span>(tmp) -1);
<a name="l00294"></a>00294 
<a name="l00295"></a>00295                     <span class="comment">/* Le o resto do arquivo */</span>
<a name="l00296"></a>00296                     <span class="keywordflow">while</span>(fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd)!=NULL){
<a name="l00297"></a>00297                         <span class="comment">/* Separa a linha lida */</span>
<a name="l00298"></a>00298                         pch = strtok(tmp, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00299"></a>00299                         <span class="comment">/* Imprime a linha lida */</span>
<a name="l00300"></a>00300                         <span class="keywordflow">while</span>(pch !=NULL){
<a name="l00301"></a>00301                             <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, pch, strlen(pch));
<a name="l00302"></a>00302                             <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot; &quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00303"></a>00303                             pch = strtok(NULL, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00304"></a>00304                 
<a name="l00305"></a>00305                 
<a name="l00306"></a>00306                         }
<a name="l00307"></a>00307             
<a name="l00308"></a>00308 
<a name="l00309"></a>00309                     }
<a name="l00310"></a>00310                     <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot;\n&quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00311"></a>00311                     fclose(fd);
<a name="l00312"></a>00312             }
<a name="l00313"></a>00313 
<a name="l00314"></a>00314         }
<a name="l00315"></a>00315             <span class="keywordflow">return</span> str-&gt;<a class="code" href="structstr.html#a1fc4ce5d6a790001388349ca5b735383">s</a>;
<a name="l00316"></a>00316 
<a name="l00317"></a>00317     }
<a name="l00318"></a>00318 }
<a name="l00319"></a>00319 
<a name="l00320"></a>00320 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00330"></a>00330 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00331"></a><a class="code" href="resposta_8h.html#a6c04d45a3b24b43c86d50889bde25d67">00331</a> <span class="keywordtype">char</span>* <a class="code" href="resposta_8c.html#a6c04d45a3b24b43c86d50889bde25d67">infoDisciplina</a>(<span class="keywordtype">char</span>* disc){
<a name="l00332"></a>00332     
<a name="l00333"></a>00333     FILE *fd;
<a name="l00334"></a>00334     <span class="keywordtype">char</span> texto[10];
<a name="l00335"></a>00335     <span class="keywordtype">string</span> <a class="code" href="structstr.html">str</a>;
<a name="l00336"></a>00336 
<a name="l00337"></a>00337     <span class="comment">/* Normaliza e obtem o nome do arquivo correspondente</span>
<a name="l00338"></a>00338 <span class="comment">     * a disciplina passada como parametro*/</span>
<a name="l00339"></a>00339     <a class="code" href="resposta_8c.html#aaf2c986b7320373a463f607a67c07365">uppercase</a>(disc);
<a name="l00340"></a>00340     strcpy(texto, disc);
<a name="l00341"></a>00341     strcat(texto, <span class="stringliteral">&quot;.txt&quot;</span>);
<a name="l00342"></a>00342 
<a name="l00343"></a>00343     fd = fopen(texto, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00344"></a>00344     <span class="comment">/* Verifica se a abertura do arquivo foi bem sucedida */</span>
<a name="l00345"></a>00345     <span class="keywordflow">if</span>(fd == NULL){
<a name="l00346"></a>00346         printf(<span class="stringliteral">&quot;Erro ao abrir o arquivo da disciplina %s.\n&quot;</span>, disc);
<a name="l00347"></a>00347         exit(-1);
<a name="l00348"></a>00348     }
<a name="l00349"></a>00349     <span class="keywordflow">else</span>{
<a name="l00350"></a>00350         <span class="keywordtype">char</span> tmp[200];
<a name="l00351"></a>00351         <span class="keywordtype">char</span> *pch;
<a name="l00352"></a>00352 
<a name="l00353"></a>00353         <span class="comment">/* Inicializa um vetor contendo a resposta */</span>
<a name="l00354"></a>00354         str = <a class="code" href="str_8c.html#a43e9efab3e78f169462b9f842c827fba">str_initialize</a>(((<span class="keywordtype">size_t</span>)<a class="code" href="resposta_8c.html#a281d136eba7bc38021f2fccbf61a633f">NUM_MAX_DISCIPLINAS</a> * <a class="code" href="resposta_8c.html#a5d429b813e4525632cd4064f5e47213e">TAM_MAX_NOME_DISCIPLINA</a>));
<a name="l00355"></a>00355         
<a name="l00356"></a>00356         <span class="comment">/* Le o titulo da disciplina */</span>
<a name="l00357"></a>00357         fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd);
<a name="l00358"></a>00358 
<a name="l00359"></a>00359         <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, tmp, <span class="keyword">sizeof</span>(tmp) -1);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361         <span class="comment">/* Le o resto do arquivo */</span>
<a name="l00362"></a>00362         <span class="keywordflow">while</span>(fgets(tmp, <span class="keyword">sizeof</span>(tmp), fd)!=NULL){
<a name="l00363"></a>00363             <span class="comment">/* Separa a linha lida */</span>
<a name="l00364"></a>00364             pch = strtok(tmp, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00365"></a>00365             <span class="comment">/* Imprime a linha lida */</span>
<a name="l00366"></a>00366             <span class="keywordflow">while</span>(pch !=NULL){
<a name="l00367"></a>00367                 <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, pch, strlen(pch));
<a name="l00368"></a>00368                 <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot; &quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00369"></a>00369                 pch = strtok(NULL, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00370"></a>00370                 
<a name="l00371"></a>00371                 
<a name="l00372"></a>00372             }
<a name="l00373"></a>00373             
<a name="l00374"></a>00374 
<a name="l00375"></a>00375         }
<a name="l00376"></a>00376         <a class="code" href="str_8c.html#a9c98046afe58b4d941f546c5a604a7de">str_concat_chararr</a>(str, <span class="stringliteral">&quot;\n&quot;</span>, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00377"></a>00377         fclose(fd);
<a name="l00378"></a>00378         <span class="keywordflow">return</span> str-&gt;<a class="code" href="structstr.html#a1fc4ce5d6a790001388349ca5b735383">s</a>;
<a name="l00379"></a>00379     }
<a name="l00380"></a>00380 }
<a name="l00381"></a>00381 
<a name="l00382"></a>00382 <span class="comment">/* --------------------------------------------------------------------------*/</span>
<a name="l00390"></a>00390 <span class="comment">/* ----------------------------------------------------------------------------*/</span>
<a name="l00391"></a><a class="code" href="resposta_8h.html#aaf2c986b7320373a463f607a67c07365">00391</a> <span class="keywordtype">void</span> <a class="code" href="resposta_8c.html#aaf2c986b7320373a463f607a67c07365">uppercase</a>(<span class="keywordtype">char</span>* sPtr){
<a name="l00392"></a>00392     <span class="keywordtype">int</span> i=0;
<a name="l00393"></a>00393     <span class="keywordflow">while</span> (sPtr[i]) {
<a name="l00394"></a>00394         sPtr[i] = toupper((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)sPtr[i]);
<a name="l00395"></a>00395         i++;
<a name="l00396"></a>00396     }
<a name="l00397"></a>00397 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Todos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Estruturas de Dados</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Arquivos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funções</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variáveis</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Definições de Tipos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Definições e Macros</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Gerado em Quarta, 25 de Abril de 2012 23:42:04 para MC823 - Laboratório de Redes: Trabalho 01 por&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>
